// components/item-choose/item-choose.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    tag:{
      type:String,
      value:""
    },
    type:{
      type:String,
      value:""
    },
    maxrenttime:{
      type:Number,
      value:8
    },
    list:{
      type:Object,
      value:{
        name:'',
        text:''
      }
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    chooseidx:0,
    timeval:1,
    price:'',
    deposit:'',
    totalprice:'',
    card: [{
      img: {
        url: "/static/images/news/avatar_1.jpg"
      },
      title: {
        text: "类型选择",
        size:38,
        color:"#000"
      },
      tag: {
        text: "普通区域柜"
      },
      header: {
        line: true
      }
    },
    {tag: {
        text: "户外手机柜"
      } },
    {tag: {
        text: "浮圈"
      }
    }
  ]
  },

  lifetimes:{
    attached(){

      var price = this.data.list[this.data.chooseidx].text;
      var deposit = this.data.list[this.data.chooseidx].context;
      this.setData({
        price:parseFloat(price),
        deposit:parseFloat(deposit),
      })
      var totalprice = parseFloat((this.data.timeval*100)*(this.data.price*100)/10000)
      this.setData({
        totalprice:totalprice
      })
    }
  },

  methods: {
    change(e){
      var price = this.data.list[this.data.chooseidx].text;
      var deposit = this.data.list[this.data.chooseidx].context;
      this.setData({
        price:parseFloat(price),
        timeval:parseFloat(e.detail.value),
        deposit:parseFloat(deposit)
      })
      var totalprice = parseFloat((this.data.timeval*100)*(this.data.price*100)/10000)
      this.setData({
        totalprice:totalprice
      })
      console.log('end total',this.data.totalprice)

    },
    sub(e){
      var index = e.currentTarget.dataset.id;
      var price = e.currentTarget.dataset.price;
      this.setData({
        chooseidx:index,
        price:parseFloat(price)
      })
      var deposit = this.data.list[this.data.chooseidx].context;
      var totalprice = parseFloat((this.data.timeval*100)*(this.data.price*100)/10000)
      this.setData({
        totalprice:totalprice,
        deposit:parseFloat(deposit)
      })
      console.log('end total',this.data.totalprice)
    },
    getType(){
      return this.data.list[this.data.chooseidx].type
    },

  }
})
